---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: cluster-apps
  namespace: flux-system
spec:
  decryption:
    provider: sops
  deletionPolicy: WaitForTermination
  interval: 1h
  path: ./kubernetes/apps
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system
    namespace: flux-system
  wait: false
  patches:
    - # Add Kustomization defaults for all child Kustomizations
      patch: |-
        apiVersion: kustomize.toolkit.fluxcd.io/v1
        kind: Kustomization
        metadata:
          name: _
        spec:
          decryption:
            provider: sops
          deletionPolicy: WaitForTermination
          patches:
            - patch: |-
                apiVersion: helm.toolkit.fluxcd.io/v2
                kind: HelmRelease
                metadata:
                  name: _
                spec:
                  install:
                    crds: CreateReplace
                    strategy:
                      name: RetryOnFailure
                  rollback:
                    cleanupOnFail: true
                    recreate: true
                  upgrade:
                    cleanupOnFail: true
                    crds: CreateReplace
                    strategy:
                      name: RemediateOnFailure
                    remediation:
                      remediateLastFailure: true
                      retries: 2
              target:
                group: helm.toolkit.fluxcd.io
                kind: HelmRelease
      target:
        group: kustomize.toolkit.fluxcd.io
        kind: Kustomization
